home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / despereaux-swings.swf / scripts / Box2D / Dynamics / Contacts / b2CircleContact.as next >
Encoding:
Text File  |  2011-10-17  |  4.6 KB  |  126 lines

  1. package Box2D.Dynamics.Contacts
  2. {
  3.    import Box2D.Collision.Shapes.b2CircleShape;
  4.    import Box2D.Collision.Shapes.b2Shape;
  5.    import Box2D.Collision.b2Collision;
  6.    import Box2D.Collision.b2ContactPoint;
  7.    import Box2D.Collision.b2Manifold;
  8.    import Box2D.Collision.b2ManifoldPoint;
  9.    import Box2D.Common.Math.b2Vec2;
  10.    import Box2D.Dynamics.b2Body;
  11.    import Box2D.Dynamics.b2ContactListener;
  12.    
  13.    public class b2CircleContact extends b2Contact
  14.    {
  15.       
  16.       private static const s_evalCP:b2ContactPoint = new b2ContactPoint();
  17.        
  18.       
  19.       private var m_manifolds:Array;
  20.       
  21.       private var m0:b2Manifold;
  22.       
  23.       public var m_manifold:b2Manifold;
  24.       
  25.       public function b2CircleContact(param1:b2Shape, param2:b2Shape)
  26.       {
  27.          var _loc3_:b2ManifoldPoint = null;
  28.          m_manifolds = [new b2Manifold()];
  29.          m0 = new b2Manifold();
  30.          super(param1,param2);
  31.          m_manifold = m_manifolds[0];
  32.          m_manifold.pointCount = 0;
  33.          _loc3_ = m_manifold.points[0];
  34.          _loc3_.normalImpulse = 0;
  35.          _loc3_.tangentImpulse = 0;
  36.       }
  37.       
  38.       public static function Destroy(param1:b2Contact, param2:*) : void
  39.       {
  40.       }
  41.       
  42.       public static function Create(param1:b2Shape, param2:b2Shape, param3:*) : b2Contact
  43.       {
  44.          return new b2CircleContact(param1,param2);
  45.       }
  46.       
  47.       override public function GetManifolds() : Array
  48.       {
  49.          return m_manifolds;
  50.       }
  51.       
  52.       override public function Evaluate(param1:b2ContactListener) : void
  53.       {
  54.          var _loc2_:b2Vec2 = null;
  55.          var _loc3_:b2Vec2 = null;
  56.          var _loc4_:b2ManifoldPoint = null;
  57.          var _loc5_:b2Body = null;
  58.          var _loc6_:b2Body = null;
  59.          var _loc7_:b2ContactPoint = null;
  60.          var _loc8_:b2ManifoldPoint = null;
  61.          _loc5_ = m_shape1.m_body;
  62.          _loc6_ = m_shape2.m_body;
  63.          m0.Set(m_manifold);
  64.          b2Collision.b2CollideCircles(m_manifold,m_shape1 as b2CircleShape,_loc5_.m_xf,m_shape2 as b2CircleShape,_loc6_.m_xf);
  65.          (_loc7_ = s_evalCP).shape1 = m_shape1;
  66.          _loc7_.shape2 = m_shape2;
  67.          _loc7_.friction = m_friction;
  68.          _loc7_.restitution = m_restitution;
  69.          if(m_manifold.pointCount > 0)
  70.          {
  71.             m_manifoldCount = 1;
  72.             _loc8_ = m_manifold.points[0];
  73.             if(m0.pointCount == 0)
  74.             {
  75.                _loc8_.normalImpulse = 0;
  76.                _loc8_.tangentImpulse = 0;
  77.                if(param1)
  78.                {
  79.                   _loc7_.position = _loc5_.GetWorldPoint(_loc8_.localPoint1);
  80.                   _loc2_ = _loc5_.GetLinearVelocityFromLocalPoint(_loc8_.localPoint1);
  81.                   _loc3_ = _loc6_.GetLinearVelocityFromLocalPoint(_loc8_.localPoint2);
  82.                   _loc7_.velocity.Set(_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y);
  83.                   _loc7_.normal.SetV(m_manifold.normal);
  84.                   _loc7_.separation = _loc8_.separation;
  85.                   _loc7_.id.key = _loc8_.id._key;
  86.                   param1.Add(_loc7_);
  87.                }
  88.             }
  89.             else
  90.             {
  91.                _loc4_ = m0.points[0];
  92.                _loc8_.normalImpulse = _loc4_.normalImpulse;
  93.                _loc8_.tangentImpulse = _loc4_.tangentImpulse;
  94.                if(param1)
  95.                {
  96.                   _loc7_.position = _loc5_.GetWorldPoint(_loc8_.localPoint1);
  97.                   _loc2_ = _loc5_.GetLinearVelocityFromLocalPoint(_loc8_.localPoint1);
  98.                   _loc3_ = _loc6_.GetLinearVelocityFromLocalPoint(_loc8_.localPoint2);
  99.                   _loc7_.velocity.Set(_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y);
  100.                   _loc7_.normal.SetV(m_manifold.normal);
  101.                   _loc7_.separation = _loc8_.separation;
  102.                   _loc7_.id.key = _loc8_.id._key;
  103.                   param1.Persist(_loc7_);
  104.                }
  105.             }
  106.          }
  107.          else
  108.          {
  109.             m_manifoldCount = 0;
  110.             if(m0.pointCount > 0 && Boolean(param1))
  111.             {
  112.                _loc4_ = m0.points[0];
  113.                _loc7_.position = _loc5_.GetWorldPoint(_loc4_.localPoint1);
  114.                _loc2_ = _loc5_.GetLinearVelocityFromLocalPoint(_loc4_.localPoint1);
  115.                _loc3_ = _loc6_.GetLinearVelocityFromLocalPoint(_loc4_.localPoint2);
  116.                _loc7_.velocity.Set(_loc3_.x - _loc2_.x,_loc3_.y - _loc2_.y);
  117.                _loc7_.normal.SetV(m0.normal);
  118.                _loc7_.separation = _loc4_.separation;
  119.                _loc7_.id.key = _loc4_.id._key;
  120.                param1.Remove(_loc7_);
  121.             }
  122.          }
  123.       }
  124.    }
  125. }
  126.